import { defineStore } from "pinia";
import request from "@/plugins/request";
export const useHomeStore = defineStore('HomeStore', () => {
    const searchContent = ref('')
    const apiInfoList = ref([])
    
    async function searchClick() {
        //检测是否内容为空，
        if (searchContent.value.trim().length) {
            // 不为空发送请求
            const {data:{data:searchResults}} = await request.get(`/apiInfo/search/${searchContent.value}`)
            setTimeout(() => {
                apiInfoList.value = searchResults
            }, 150);
        } else {
            ElMessage.warning('请输入搜索内容')
        }
    }
    async function getApiList() {
        const { data:{data} } = await request.get('/apiInfo/list')
        apiInfoList.value = data
    }
    getApiList()
    
    return {
        apiInfoList,
        searchContent,
        searchClick,
        getApiList,
    }
})